package com.zr.task.dialog;


import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.TextView;
import com.zh.model.task.home.CabinetBean;
import com.zr.task.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CabDialog extends Dialog {
    @BindView(R.id.tv_subject)
    TextView tvSubject;
    @BindView(R.id.tv_t_class)
    TextView tvTClass;
    @BindView(R.id.tv_teacher)
    TextView tvTeacher;
    @BindView(R.id.tv_student)
    TextView tvStudent;
    @BindView(R.id.tv_s_class)
    TextView tvSClass;
    @BindView(R.id.tv_submit_count)
    TextView tvSubmitCount;
    @BindView(R.id.tv_mistake_count)
    TextView tvMistakeCount;

    private CabinetBean mBean;
    /**
     * 空闲时间
     */
    private static final Long MILLISINFUTURE = (long) 61 * 1000;
    /**
     * 倒计时间隔
     */
    private static final Long COUNTDOWNINTERVAL = (long)  1000;
    private CountDownTimer countTimer;

    public CabDialog(Context context, int themeResId, CabinetBean mBean) {
        super(context, themeResId);
        this.mBean = mBean;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_cab);
        ButterKnife.bind(this);
        tvSubject.setText(mBean.getSubjectName());
        tvTClass.setText(mBean.getGradeClassName());
        tvTeacher.setText(mBean.getTeacherName());
        StringBuilder student = new StringBuilder();
        StringBuilder stuClass = new StringBuilder();
        for(int i = 0;i<mBean.getStuVOS().size();i++){
            student.append(mBean.getStuVOS().get(i).getStuName()) ;
            stuClass.append(mBean.getStuVOS().get(i).getGradeClassName());
            if(i!=mBean.getStuVOS().size()-1){
                student.append(" / ");
                stuClass.append(" / ");
            }
        }
//        student.append(" / ");
//        stuClass.append(" / ");
//        for(int i = 0;i<3;i++){
//            student.append("张三") ;
//            stuClass.append("高一2班");
//            if(i!=2){
//                student.append(" / ");
//                stuClass.append(" / ");
//            }
//        }
        tvStudent.setText(student);
        tvSClass.setText(stuClass);
        tvSubmitCount.setText(mBean.getCount() + "人");
        tvMistakeCount.setText(mBean.getMissentCount() + "人");
        if(mBean.getMissentCount()!=0)
            tvMistakeCount.setTextColor(Color.RED);
        initCountTimer();
    }

    private void initCountTimer() {
        countTimer = new CountDownTimer(MILLISINFUTURE, COUNTDOWNINTERVAL) {
            @Override
            public void onTick(long millisUntilFinished) {
            }

            @Override
            public void onFinish() {
                cancel();
            }
        };
        countTimer.start();
    }

    @OnClick({R.id.ll_cancle})
    public void onClick(View view) {
        countTimer.cancel();
        cancel();
    }

}
